<template>
  <div>
    <div style="margin: 5em auto;width: 400px;">
      <t-space direction="vertical" style="width: 100%">
        <Logo/>
        <template v-if="panel === 'login'">
          <div>
            <span>没有账号吗？</span>
            <t-link theme="primary" @click="panel = 'register'">注册新账号</t-link>
          </div>
          <Login/>
        </template>
        <template v-else>
          <div>
            <span>已有账号？</span>
            <t-link theme="primary" @click="panel = 'login'">立即登录</t-link>
          </div>
          <Register/>
        </template>
        <template v-if="loginOk" style="margin-top: 1em">
          <t-button size="large" block theme="success" @click="$router.push({path:'/admin/my/info'})">
            当前已登录账号，直接进入后台
          </t-button>
        </template>
      </t-space>
    </div>
  </div>
</template>
<script setup lang="ts">
import Logo from "../../assets/svg/assets-t-logo.svg"
import Login from "./components/login.vue"
import Register from "./components/register.vue"
import {onMounted, ref} from "vue";
import {getDefaultStore} from "../../store/modules/default";
import {useRouter} from "vue-router";
import {curTimeUnix} from "../../tool/time";

const defaultStore = getDefaultStore()
const router = useRouter()
const panel = ref("login")
const loginOk = ref(false)

onMounted(() => {
  if (curTimeUnix() <= defaultStore.tokenExpirationTime - 60) {
    loginOk.value = true
  }
})
</script>